﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace CamelotSQLCommander
{
    public class Helpers
    {
        public static string base64_encode(byte[] data)
        {
            if (data == null)
                throw new ArgumentNullException("data");
            return Convert.ToBase64String(data);
        }

        public static byte[] gzdeflate(byte[] str)
        {
            using (var output = new MemoryStream())
            {
                using (var gzip = new DeflateStream(output, CompressionMode.Compress))
                {
                    using (var writer = new StreamWriter(gzip))
                    {
                        writer.Write(str);
                    }
                }
                return output.ToArray();
            }
        }

        public static byte[] gzdeflate(string str)
        {
            using (var output = new MemoryStream())
            {
                using (var gzip = new DeflateStream(output, CompressionMode.Compress))
                {
                    using (var writer = new StreamWriter(gzip))
                    {
                        writer.Write(str);
                    }
                }
                return output.ToArray();
            }
        }

    }
}
